package com.mycat.web.common;

import com.mycat.dao.entity.auth.Admin;
import com.mycat.dao.entity.ucenter.Customer;
import com.mycat.web.content.shiro.CustomerUserRealm;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;

import java.util.List;

/**
 * @author roger.
 * @email luojie@yzworld.cn
 * @date 2016/10/8
 */
public class BaseController {

    /**
     * 获取登录用户id
     *
     * @return ID
     * @throws LoginTimeOutException
     */
    public Integer getLoginId() throws LoginTimeOutException {
        Session session = SecurityUtils.getSubject().getSession();
        Object loginId = session.getAttribute(CustomerUserRealm.SESSION_LOGIN_USER_ID);
        if (null == loginId) {
            throw new LoginTimeOutException();
        }
        return (Integer) loginId;
    }

    /**
     * 获取登录用户
     *
     * @return Admin
     * @throws LoginTimeOutException
     */
    public Customer getLoginUser() throws LoginTimeOutException {
        Session session = SecurityUtils.getSubject().getSession();
        Object customer = session.getAttribute(CustomerUserRealm.SESSION_LOGIN_USER);
        if (null == customer) {
            throw new LoginTimeOutException();
        }
        return (Customer) customer;
    }

}
